package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.net.ssl.SSLEngineResult;

/**
 * @Description ShopController
 * @Author lyh
 * @Date 2024-09-26
 */
//商家端和用户端的类名都是shopController，冲突，起别名解决
//Annotation-specified bean name 'shopController' for bean class [com.sky.controller.user.ShopController] conflicts with existing
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "商家端店铺相关管理")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 修改店铺状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("修改店铺状态")
    public Result<String> setShopStatus(@PathVariable Integer status){
        redisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS_KEY, status);
        return Result.success();
    }

    /**
     * 查看店铺状态
     * @return
     */
    @ApiOperation("查看店铺状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
      Integer status= (Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
      //之前未设置店铺状态，将查询的状态设为0
      if(status==null){
         status=0;
      }
      return Result.success(status);
    }
}
